package com.chaoyi.service.Impl;

import java.io.IOException;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.Part;

import org.springframework.stereotype.Service;

import com.chaoyi.config.WSUploadConfig;
import com.chaoyi.dao.mysql.PortraitVideoMapper;
import com.chaoyi.model.PortraitVideo;
import com.chaoyi.service.PortraitVideoService;
import com.chaoyi.util.UUIDUtil;
import com.chaoyi.util.oss.ApkOSSConfigure;
import com.chaoyi.util.oss.ApkOSSManageUtil;
import com.chaoyi.util.qiniu.UploadFileQiNiu;

@Service
public class PortraitVideoServiceImpl implements PortraitVideoService{
	@Resource
	PortraitVideoMapper portraitVideoMapper;
	@Override
	public List<PortraitVideo> findList(String offset, String limit) {
		return portraitVideoMapper.findList(offset,limit);
	}
	
	@Override
	public int findCount() {
		return portraitVideoMapper.findCount();
	}
	@Override
	public int addVideoSave(PortraitVideo entity) {
		return portraitVideoMapper.addVideoSave(entity);
	}
	
	@Override
	public String uploadClassifyImg2WSCDN(Part uploadFile) throws IOException, Exception {
		String exten = uploadFile.getSubmittedFileName().substring(uploadFile.getSubmittedFileName().lastIndexOf("."));
		String fileName = UUIDUtil.getUUID() + exten;
//		return ApkOSSManageUtil.uploadFile(new ApkOSSConfigure(), uploadFile, WSUploadConfig.portraitImgUrlPath,
//				fileName);
		return UploadFileQiNiu.uploadFile(uploadFile, WSUploadConfig.portraitImgUrlPath, fileName);
	}

	@Override
	public String uploadClassifyVideo2WSCDN(Part uploadFile) throws IOException, Exception {
		String exten = uploadFile.getSubmittedFileName().substring(uploadFile.getSubmittedFileName().lastIndexOf("."));
		String fileName = UUIDUtil.getUUID() + exten;
//		return ApkOSSManageUtil.uploadFile(new ApkOSSConfigure(), uploadFile, WSUploadConfig.portraitVideoPath,
//				fileName);
		return UploadFileQiNiu.uploadFile(uploadFile, WSUploadConfig.portraitVideoPath, fileName);
	}
	@Override
	public PortraitVideo findVideoOne(int id) {
		return portraitVideoMapper.findVideoOne(id);
	}
	@Override
	public int alertVideoSave(PortraitVideo entity) {
		return portraitVideoMapper.alertVideoSave(entity);
	}
	
	@Override
	public int deleteVideo(int id) {
		return portraitVideoMapper.deleteVideo(id);
	}

}
